# -*- coding: utf-8 -*-
# @Time : 2024/2/19 17:47
# @Author : ZH
# @File : 34.py
# @Software: PyCharm
class Solution(object):
    def searchRange(self, nums, target):
        """
        :type nums: List[int]
        :type target: int
        :rtype: List[int]
        """
        if not nums or target > nums[-1] or target < nums[0] or target not in nums: return [-1, -1]
        if target == nums[0] and target == nums[-1]: return [0, len(nums)-1]
        l = 0
        r = len(nums) - 1
        z = int(len(nums) / 2)
        while True:
            if target == nums[l] or target == nums[r]:
                index = l if target == nums[l] else r
                break
            if nums[z] > target:
                r = z
            elif nums[z] < target:
                l = z
            else:
                index = z
                break
            z = int((r+l)/2)
        # 找到值 开始检索位置上下限
        l_ = index
        while True:
            if l_ == -1:
                # l_ -= 1
                break
            if nums[l_] == target:
                l_ -= 1
            else:
                break
        r_ = index
        while True:
            if r_ == len(nums):
                break
            if nums[r_] == target:
                r_ += 1
            else:
                break
        return [l_+1, r_-1]

if __name__ == '__main__':
    so = Solution()
    # nums = [1,2,3]
    nums = [0,0,0,1,2,3]
    # target = 3
    target = 0
    z = so.searchRange(nums=nums, target=target)
    print(z)
